export default {
  namespace: 'topics',
  state: {
    page: 1,
    list: [],
  },
  reducers: {
    update(state, { data }) {
      return {
        page: state.page,
        list: data,
      };
    },
    nextPage({ page, list }) {
      return {
        list,
        page: page + 1,
      };
    },
  },
  effects: {
    *getData({ page }, { call, put }) {
      const res = yield call(fetch, 'https://cnodejs.org/api/v1/topics?limit=10&page=' + page);
      console.log(res);
      const data = yield res.json();
      yield put({
        type: 'update',
        data: data.data,
      });
    },
  },
};
